package com.example.wisdomclassroomapi.common.util;

import com.example.wisdomclassroomapi.domain.vo.WxAppLoginInfoVo;

/**
 * 获取微信小程序登录信息工具类
 */
public final class WxAppLoginInfoUtil {
    private static final ThreadLocal<WxAppLoginInfoVo> threadLocal = new ThreadLocal<>();

    public static void set(WxAppLoginInfoVo loginInfoVo){
        threadLocal.remove();
        threadLocal.set(loginInfoVo);
    }

    public static void remove() {
        threadLocal.remove();
    }

    public static WxAppLoginInfoVo get() {
        return threadLocal.get();
    }

    public static String getUserId() {
        WxAppLoginInfoVo loginInfoVo = threadLocal.get();
        return loginInfoVo == null ? null : loginInfoVo.getUserId();
    }
}
